package com.ikas.ai.server.module.morningpaper.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.server.aop.Pageable;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.morningpaper.model.dto.FailureRecord;
import com.ikas.ai.server.module.morningpaper.service.FailureRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: wang.qining
 * @date: 2024/2/2 9:46
 */
@RestController
@RequestMapping("/failureRecord")
public class FailureRecordController extends AbstractBean {
    @Autowired
    private FailureRecordService service;

    /**
     * 新增
     * @param failureRecord
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody FailureRecord failureRecord) {
        return JsonResult.ok(service.add(failureRecord));
    }

    /**
     * 修改
     * @param failureRecord
     * @return
     */
    @PostMapping("/update")
    public JsonResult update(@RequestBody FailureRecord failureRecord) {
        return JsonResult.ok(service.updateById(failureRecord));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable("id") Long id) {
        return JsonResult.ok(service.removeById(id));
    }

    /**
     * 获取当前数据库中数据里从最小年份开始到今年的年份列表
     * @return
     */
    @GetMapping("/getYears")
    public JsonResult getYears() {
        return JsonResult.ok(service.getYears());
    }

    /**
     * 分页接口
     * @return
     */
    @GetMapping("/pageList/{year}")
    @Pageable(sortType = "desc")
    public JsonResult pageList(@PathVariable("year") Integer year) {
        return JsonResult.ok(service.pageList(year));
    }

    /**
     * 统计工况数据
     */
    @GetMapping("/statistics/{year}")
    public JsonResult statistics(@PathVariable("year") Integer year) {
        return JsonResult.ok(service.statistics(year));
    }
}
